
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       fms_sensors.c
  * @author     baiyang
  * @date       2022-10-7
  ******************************************************************************
  */

/*----------------------------------include-----------------------------------*/
#include "fms.h"
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/

/*---------------------------------prototype----------------------------------*/

/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
// return true if rangefinder_alt can be used
bool fms_rangefinder_alt_ok()
{
    return (fms.rangefinder_state.enabled && fms.rangefinder_state.alt_healthy);
}

// return true if rangefinder_alt can be used
bool fms_rangefinder_up_ok()
{
    return (fms.rangefinder_up_state.enabled && fms.rangefinder_up_state.alt_healthy);
}

/*
  get inertially interpolated rangefinder height. Inertial height is
  recorded whenever we update the rangefinder height, then we use the
  difference between the inertial height at that time and the current
  inertial height to give us interpolation of height from rangefinder
 */
bool fms_get_rangefinder_height_interpolated_cm(int32_t* ret)
{
    if (!fms_rangefinder_alt_ok()) {
        return false;
    }
    *ret = lpf_get_output(&fms.rangefinder_state.alt_cm_filt);
    float inertial_alt_cm = ahrs_get_position_z_up_cm(fms.ahrs);
    *ret += inertial_alt_cm - fms.rangefinder_state.inertial_alt_cm;
    return true;
}

/*------------------------------------test------------------------------------*/


